import { siteTokenKey, siteOpenidKey, siteKey } from "@/config/settings";

/**
 * @description: 获取本地Token
 */
export const getToken = () => localStorage.getItem(siteTokenKey);

/**
 * @description: 设置存储本地Token
 */
export const setToken = (token) => {
	localStorage.setItem(siteTokenKey, token);
};

/**
 * @description: 移除本地Token
 */
export const removeToken = () => {
	localStorage.removeItem(siteTokenKey);
};

/**
 * @description: 获取本地openid
 */
export const getOpenid = () => localStorage.getItem(siteOpenidKey);

/**
 * @description: 设置存储本地openid
 */
export const setOpenid = (token) => {
	localStorage.setItem(siteOpenidKey, token);
};

/**
 * @description: 移除本地openid
 */
export const removeOpenid = () => {
	localStorage.removeItem(siteOpenidKey);
};

/**
 * @description: 获取本地localStorage
 */
export const getStorage = (key) => {
	try {
		return JSON.parse(localStorage.getItem(`${siteKey}${key}`));
	} catch (err) {
		console.log(err);
	}
};

/**
 * @description: 设置存储本地localStorage
 */
export const setStorage = (key, data) => {
	try {
		localStorage.setItem(`${siteKey}${key}`, JSON.stringify(data));
	} catch (err) {
		console.log(err);
	}
};

/**
 * @description: 移除本地localStorage
 */
export const removeStorage = (key) => {
	localStorage.removeItem(`${siteKey}${key}`);
};
